package admin

import (
	"duoke/model"
	"duoke/service"
	"duoke/tables"
	"duoke/utils/response"
	"duoke/utils/valid"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var HomeVideo = new(homeVideoCtl)

type homeVideoCtl struct{}

func (ctl *homeVideoCtl) List(c *gin.Context) {
	var req model.ReqList
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	list, count, err := service.HomeVideo.List(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
func (ctl *homeVideoCtl) Save(c *gin.Context) {
	var req tables.HomeVideo
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	err := service.HomeVideo.Save(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "保存成功", "")
}
func (ctl *homeVideoCtl) Del(c *gin.Context) {
	var req model.ReqId
	if err := c.ShouldBindJSON(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	err := service.HomeVideo.Del(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "删除成功", nil)
}
